/**
 * author:Administrator
 * date:2013-5-21
 */
package com.roc.web.action.merinfo;

import java.util.ArrayList;
import java.util.List;

import com.roc.page.BaseSearchCondition;
import com.roc.page.WhereHQLFieldBean;
import com.roc.util.Constance;

/**
 * @author Administrator
 *
 */
public class MerchantSearchCondition extends BaseSearchCondition {
	
	
	
	private String  orgCode;//机构号
	private String[] agentId;//所属代理商
	private String merchantNo;//商户号
	private String merchantName;//商户名称
	private String  merBrName; //名称中文简称
	private String areaCode;//地区
	private String  cardNo; //身份证
	private String  mccName;//mcc
	
	private String  rateType;//扣率类型
	private String  minDate;//入网时间
	private String  maxDate;//入网时间
	private String  midType;//商户类型
	private String  midStatus;//商户状态
	private String  cycle;//结算周期
	private String  addr;//商户地址
	
	private String setMaxTime;//激活截止时间
	private String setMixTime;//激活初始时间
	private String persalName;//法人
	private String personalPhone;//法人电话
	private String insertContact;//业务联系人
	private String tel;//业务联系人电话
	
	private String realName;//代理商中文
	
	private String queryOpr;//用户的账号名称
	
	/* (non-Javadoc)
	 * @see com.roc.page.BaseSearchCondition#getOrderPartOfHQL()
	 */
	@Override
	protected String getOrderPartOfHQL() {
		// TODO Auto-generated method stub
		
		return " order by em.dt_Create  DESC  ";
	}

	/* (non-Javadoc)
	 * @see com.roc.page.BaseSearchCondition#getRowCountHQL()
	 */
	@Override
	protected String getRowCountHQL() {
		
		return " select count(*) from esmidinfo_tmp e,esmidinfo_tmp_merinfo em,t_operators op where e.mid=em.merchant and op.id=em.agent_id  ";
	}

	/* (non-Javadoc)
	 * @see com.roc.page.BaseSearchCondition#getSearchHQL()
	 */
	@Override
	protected String getSearchHQL() {
		String  sql="SELECT e.mid,e.mer_name,e.mer_br_name,e.mer_kind,e.flag ,      "
				+"e.rsv1,e.rsv3,e.inter_contact,em.peraonal_phone,em.personal_name,  "
				+"em.cycleid,em.card_type,em.card_no,e.addr,em.area_code,em.agent_id, "
				+"e.COMM_RATE,e.COMM_MODE,e.comm_amt,em.BUSINESS_LICENCES,op.REAL_NAME  FROM esmidinfo_tmp e,esmidinfo_tmp_merinfo em,t_operators op "
				+"WHERE e.mid=em.merchant and op.id=em.agent_id  ";
		return sql;
	}

	/* (non-Javadoc)
	 * @see com.roc.page.BaseSearchCondition#getWhereHQLFieldBeanList()
	 */
	@Override
	protected List<WhereHQLFieldBean> getWhereHQLFieldBeanList() {
		List<WhereHQLFieldBean> filedBeanList = new ArrayList<WhereHQLFieldBean>();
		
		if(Constance.isNotEmpty(merchantNo)){ //商户号
			filedBeanList.add(new WhereHQLFieldBean("e.mid", merchantNo.trim(), "=", false));
		}
		if(Constance.isNotEmpty(merchantName)){ //商户名称 （模糊）
			filedBeanList.add(new WhereHQLFieldBean("e.mer_name", merchantName.trim(), "like", false,"ALL"));
		}
		if(Constance.isNotEmpty(merBrName)){ //商户名称 （模糊）
			filedBeanList.add(new WhereHQLFieldBean("e.mer_br_name", merBrName.trim(), "like", false,"ALL"));
		}
		if(Constance.isNotEmpty(areaCode)){ //地区
			if(!areaCode.equals("99")){
				filedBeanList.add(new WhereHQLFieldBean("em.area_code", areaCode.trim(), "=", false));
			}
			
		}
		if(Constance.isNotEmpty(cardNo)){ //法人身份证号
			filedBeanList.add(new WhereHQLFieldBean("em.card_no", cardNo.trim(), "=", false));
		}
		if(Constance.isNotEmpty(orgCode)&&!"99".equals(orgCode)){ //机构号
			filedBeanList.add(new WhereHQLFieldBean("e.belong_branch", orgCode.trim(), "=", false));
		}
		if(Constance.isNotEmpty(mccName)){//mcc
			filedBeanList.add(new WhereHQLFieldBean("e.mcc", mccName.trim(), "=", false));
		}
		if(Constance.isNotEmpty(rateType) && !rateType.equals("99")){ //扣率类型
			filedBeanList.add(new WhereHQLFieldBean("e.COMM_MODE", rateType.trim(), "=", false));
		}
		if(Constance.isNotEmpty(minDate)&&Constance.isNotEmpty(maxDate)){ //入网时间
			filedBeanList.add(new WhereHQLFieldBean("e.JOIN_DATE",minDate,">=", false));
       	    filedBeanList.add(new WhereHQLFieldBean("e.JOIN_DATE",maxDate,"<=", false));
		}
		if(Constance.isNotEmpty(midType)&&!"99".equals(midType)){ //商户类型
			filedBeanList.add(new WhereHQLFieldBean("e.MER_KIND", midType.trim(), "=", false));
		}
		if(Constance.isNotEmpty(midStatus)&&!"99".equals(midStatus)){ //商户状态
			filedBeanList.add(new WhereHQLFieldBean("e.flag", midStatus.trim(), "=", false));
		}
		if(Constance.isNotEmpty(cycle)&&!"99".equals(cycle)){ //商户结算周期
			filedBeanList.add(new WhereHQLFieldBean("em.CYCLEID", cycle.trim(), "=", false));
		}
		if(Constance.isNotEmpty(addr)){ //商户地址 （模糊）
			filedBeanList.add(new WhereHQLFieldBean("e.addr", addr.trim(), "like", false,"ALL"));
		}
		if(Constance.isNotEmpty(realName)){
			filedBeanList.add(new WhereHQLFieldBean("op.REAL_NAME", realName.trim(), "like", false,"ALL"));
		}
        if(agentId!=null&&agentId.length >0){//代理商
        	filedBeanList.add(new WhereHQLFieldBean("em.agent_id IN("+Constance.getArrayContent(agentId)+")"));
        }
        if(Constance.isNotEmpty(setMixTime)){ //激活时间
			filedBeanList.add(new WhereHQLFieldBean("e.SETTIME",setMixTime,">=", false));
		}
        if(Constance.isNotEmpty(setMaxTime)){ //激活时间
       	    filedBeanList.add(new WhereHQLFieldBean("e.SETTIME",setMaxTime,"<=", false));
		}
        if(Constance.isNotEmpty(persalName)){ //法人姓名
       	    filedBeanList.add(new WhereHQLFieldBean("em.PERSONAL_NAME",persalName,"LIKE", false,"ALL"));
		}
        if(Constance.isNotEmpty(personalPhone)){ //法人电话
       	    filedBeanList.add(new WhereHQLFieldBean("em.PERAONAL_PHONE",personalPhone.trim(),"=", false));
		}
        if(Constance.isNotEmpty(insertContact)){ //业务联系人
       	    filedBeanList.add(new WhereHQLFieldBean("e.INTER_CONTACT",insertContact.trim(),"LIKE", false,"ALL"));
		}
        if(Constance.isNotEmpty(tel)){ //业务联系人电话
       	    filedBeanList.add(new WhereHQLFieldBean("e.tel",tel.trim(),"=", false));
		}
        if(Constance.isNotEmpty(queryOpr)){ //查询的用户账号  业务员的用户使用
       	    filedBeanList.add(new WhereHQLFieldBean("em.operators",queryOpr.trim(),"=", false));
		}
		return filedBeanList;
	}

public static void main(String[] args) {
	String[] str={"1","2","3"};
	String  a=Constance.getArrayContent(str);
	System.out.println(a);
}

	

	public String getMerchantNo() {
		return merchantNo;
	}

	public void setMerchantNo(String merchantNo) {
		this.merchantNo = merchantNo;
	}

	public String getMerchantName() {
		return merchantName;
	}

	public void setMerchantName(String merchantName) {
		this.merchantName = merchantName;
	}

	public String getAreaCode() {
		return areaCode;
	}

	public void setAreaCode(String areaCode) {
		this.areaCode = areaCode;
	}


	public String getMerBrName() {
		return merBrName;
	}

	public void setMerBrName(String merBrName) {
		this.merBrName = merBrName;
	}

	public String getCardNo() {
		return cardNo;
	}

	public void setCardNo(String cardNo) {
		this.cardNo = cardNo;
	}

	public String getOrgCode() {
		return orgCode;
	}

	public void setOrgCode(String orgCode) {
		this.orgCode = orgCode;
	}

	public String[] getAgentId() {
		return agentId;
	}

	public void setAgentId(String[] agentId) {
		this.agentId = agentId;
	}

	public String getMccName() {
		return mccName;
	}

	public void setMccName(String mccName) {
		this.mccName = mccName;
	}

	public String getRateType() {
		return rateType;
	}

	public void setRateType(String rateType) {
		this.rateType = rateType;
	}

	

	public String getMidType() {
		return midType;
	}

	public void setMidType(String midType) {
		this.midType = midType;
	}

	public String getMidStatus() {
		return midStatus;
	}

	public void setMidStatus(String midStatus) {
		this.midStatus = midStatus;
	}

	public String getCycle() {
		return cycle;
	}

	public void setCycle(String cycle) {
		this.cycle = cycle;
	}

	public String getAddr() {
		return addr;
	}

	public void setAddr(String addr) {
		this.addr = addr;
	}

	public String getMinDate() {
		return minDate;
	}

	public void setMinDate(String minDate) {
		this.minDate = minDate;
	}

	public String getMaxDate() {
		return maxDate;
	}

	public void setMaxDate(String maxDate) {
		this.maxDate = maxDate;
	}

	public String getSetMaxTime() {
		return setMaxTime;
	}

	public void setSetMaxTime(String setMaxTime) {
		this.setMaxTime = setMaxTime;
	}

	public String getSetMixTime() {
		return setMixTime;
	}

	public void setSetMixTime(String setMixTime) {
		this.setMixTime = setMixTime;
	}

	public String getPersalName() {
		return persalName;
	}

	public void setPersalName(String persalName) {
		this.persalName = persalName;
	}

	public String getPersonalPhone() {
		return personalPhone;
	}

	public void setPersonalPhone(String personalPhone) {
		this.personalPhone = personalPhone;
	}

	public String getInsertContact() {
		return insertContact;
	}

	public void setInsertContact(String insertContact) {
		this.insertContact = insertContact;
	}

	public String getTel() {
		return tel;
	}

	public void setTel(String tel) {
		this.tel = tel;
	}

	public String getRealName() {
		return realName;
	}

	public void setRealName(String realName) {
		this.realName = realName;
	}

	public String getQueryOpr() {
		return queryOpr;
	}

	public void setQueryOpr(String queryOpr) {
		this.queryOpr = queryOpr;
	}


}
